package com.sino.operation.service.business;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.sino.operation.Exception.sinoexception.TerminalTaskException;
import com.sino.operation.Exception.sinoexception.TranslistNoExite;
import com.sino.operation.commons.ConstantValue;
import com.sino.operation.commons.commonEnum.PostEgCnEnum;
import com.sino.operation.commons.commonEnum.PostInfoEnum;
import com.sino.operation.commons.commonEnum.TaskState;
import com.sino.operation.commons.response.CenterResponseEnum;
import com.sino.operation.config.persistence.MyPersistence;

import com.sino.operation.entity.*;
import com.sino.operation.mapper.*;
import com.sino.operation.param.inner.*;
import com.sino.operation.service.basic.RedisTaskUserService;
import com.sino.operation.service.business.inter.TaskChoiceService;
import com.sino.operation.service.impl.BizTaskPoolServiceImpl;
import com.sino.operation.service.impl.BizTaskReleaseServiceImpl;
import com.sino.operation.util.*;
import com.sino.operation.vo.CompleteFlowParam;


import com.sino.operation.vo.TaskGetParam;
import com.sino.operation.vo.current.InfoInput;
import com.sino.operation.vo.current.TaskOtherCompleteParam;
import com.sino.operation.vo.inner.ResponseHead;
import com.sino.operation.vo.inner.ResponseMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;


import javax.validation.constraints.NotBlank;
import java.util.*;


/**
 * @ClassName TaskChoiceServiceImpl
 * @Description 任务的暂挂、解挂、释放
 * @Author 北陈
 * @Date 2021/10/11 11:23
 * @Version 1.0
 */
@Slf4j
@Service
public class TaskChoiceServiceImpl implements TaskChoiceService {

    @Autowired(required = false)
    private TransNodeServiceMapper transNodeServiceMapper;

    @Autowired
    private StringRedisTemplate redisTemplate;


    @Autowired
    private RedisTaskUserService redisTaskUserService;

    @Autowired
    private BizTaskPoolServiceImpl taskPoolService;

    @Autowired
    private BizTaskReleaseServiceImpl bizTaskReleaseService;

    @Autowired
    MyPersistence myPersistence;

    @Autowired(required = false)
    private BizTranslistMapper bizTranslistMapper;

    @Autowired(required = false)
    private SysAbMessageMapper sysAbMessageMapper;

    @Autowired(required = false)
    private BizOperateLogMapper bizOperateLogMapper;

    @Autowired(required = false)
    private BizTaskPoolMapper bizTaskPoolMapper;
    /**
     * 获取任务
     *
     * @param taskGetParam
     * @return
     */
    @Override
    public ResponseMessage getTask(TaskGetParam taskGetParam) throws Exception {

        ResponseHead responseHead = new ResponseHead();
        ResponseMessage responseMessage = new ResponseMessage();
        String tellerPost = taskGetParam.getPostNo();
        String tellerCode = taskGetParam.getCenterTellerNo();
        //按照常理来说，一个sql就能查三个集合，这里拆开，查三次，方便后面维护的理解并调整
        //查询已经被自身获取过的任务
        SysAbMessage abMessage = taskPoolService.getMessageByTellerCode(tellerCode);
        //空闲任务存在优先级，自己释放过的任务优先不再获取
        if (abMessage == null) {
            //查询自己从未释放的空闲任务
            abMessage = taskPoolService.getMessageByNotRelease(tellerPost, tellerCode);
        }
        if (abMessage == null) {
            //查询自己有无任务被释放过的空闲任务
            abMessage = taskPoolService.getMessageByRelease(tellerPost, tellerCode);
        }
        if (abMessage == null) {
            //获取任务报文为空，将用户注册进待获取任务列表
            //redis存储用户信息
            redisTaskUserService.addUserData(tellerPost, tellerCode);
            log.info("用户:" + tellerCode + "进入redis队列");
        }

        if (abMessage != null) {
            String journalNo = abMessage.getJournalNo();
            BizTaskPool bizTaskPool = taskPoolService.selectTaskByJournalNo(abMessage.getJournalNo());//获取推送的任务
            String tranCode = bizTaskPool.getTransCode();
            String postNo = taskGetParam.getPostNo();
            String methodName = PostEgCnEnum.getValue(postNo);
            Object result = ReflectExecuteUtil.executeGetTask("Exec_" + tranCode, "execute"+methodName+"Task", journalNo,abMessage);
            Map<String, String> map = bizTranslistMapper.selectMapById(journalNo);
            String imageId = map.get("IMAGE_ID");//影像套号
            String transName = map.get("TRANS_NAME");//交易名
            String productType = map.get("TRANS_TYPE");//交易类型（产品类型）
            String nodeName = bizTaskPool.getNodeName();//节点名
            String taskId = bizTaskPool.getTaskId();//任务号
            String transCode = bizTaskPool.getTransCode();//交易号
            responseHead.setImageId(imageId);
            responseHead.setJournalNo(journalNo);
            responseHead.setNodeName(nodeName);
            responseHead.setTaskId(taskId);
            responseHead.setTranCode(transCode);
            responseHead.setTranName(transName);
            responseHead.setProductType(productType);
            responseMessage.setResponseHead(responseHead);
            responseMessage.setBody(result);
            //其实两条sql可以写在一起
            //将任务状态、获取人填充
            taskPoolService.updateTaskState(taskId, TaskState.TaskState3.getValue(), true, tellerCode);
            //将不能再被获取人存入
            List<BizTaskPool> bizTaskPools = taskPoolService.selectList(journalNo);
            if (bizTaskPools.size()>1){
                taskPoolService.updateNotTellerCode(journalNo, taskId, tellerCode);
            }
        }

        return responseMessage;
    }


    /**
     * 任务暂挂
     *
     * @param taskChoiceOtherParam
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void taskSuspend(TaskChoiceOtherParam taskChoiceOtherParam) {
        taskPoolService.updateTaskState(taskChoiceOtherParam.getTaskId(), TaskState.TaskState2.getValue(), true, null);
        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setId(StringUtil.getId());
        bizOperateLog.setJournalNo(taskChoiceOtherParam.getJournalNo());
        bizOperateLog.setTellerNo(taskChoiceOtherParam.getCenterTellerNo());
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerPost(taskChoiceOtherParam.getPostNo());
        bizOperateLog.setTaskId(taskChoiceOtherParam.getTaskId());
        bizOperateLog.setCenterNum(taskChoiceOtherParam.getCenterNo());
        bizOperateLog.setOperReason(taskChoiceOtherParam.getReason());
        List<Object> list = new ArrayList<>();
        list.add(bizOperateLog);
        myPersistence.save(list);
    }

    /**
     * 任务解挂
     *
     * @param taskId
     */
    @Override
    public void taskResume(String taskId) {
        taskPoolService.updateTaskState(taskId, TaskState.TaskState1.getValue(), true, null);
    }

    /**
     * 任务释放
     *
     * @param taskChoiceOtherParam
     */
    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void taskRelease(TaskChoiceOtherParam taskChoiceOtherParam) {
        taskPoolService.updateTaskState(taskChoiceOtherParam.getTaskId(), TaskState.TaskState1.getValue(), false, null);
        BizTaskRelease bizTaskRelease = new BizTaskRelease();
        bizTaskRelease.setId(StringUtil.getId());
        bizTaskRelease.setJournalNo(taskChoiceOtherParam.getJournalNo());
        bizTaskRelease.setTellerCode(taskChoiceOtherParam.getCenterTellerNo());
        bizTaskReleaseService.save(bizTaskRelease);
    }

    /**
     * @param taskBackParam
     * @return java.lang.String
     * @description {任务回退}
     * @author 北陈
     * @date 2021/10/11 0011 23:32
     **/
    @Override
    public String taskBack(TaskBackParam taskBackParam) throws Exception {

        //region 根据交易码以及节点查询数据库或者缓存中的方法名字，然后去调用相应方法
        TaskBackPublicParam taskBackPublicParam = taskBackParam.getTaskBackPublicParam();
        String nodeName = taskBackPublicParam.getNodeName();
        String tranCode = taskBackPublicParam.getTranCode();
        String centerTellerNo = taskBackPublicParam.getCenterTellerNo();
        String postNo = taskBackPublicParam.getPostNo();
        String taskId = taskBackPublicParam.getTaskId();
        Map<String, Object> varMap = new HashMap<>(16);
        String journalNo = taskBackPublicParam.getJournalNo();
        BizTranslist bizTranslist = getBizTransListByJournalNo(journalNo);
        SysAbMessage sysAbMessage = getSysAbMessageByJournalNo(journalNo);
        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerNo(centerTellerNo);
        bizOperateLog.setCenterNum(bizTranslist.getCenterNo());
        bizOperateLog.setOrganId(bizTranslist.getOrgCode());
        bizOperateLog.setTellerPost(postNo);
        bizOperateLog.setFlowId(bizTranslist.getFlowId());
        bizOperateLog.setTaskId(taskId);
        CompleteFlowParam completeFlowParam = new CompleteFlowParam();
        PersistenceUtil persistenceUtil = ReflectExecuteUtil.execute("Exec_" + tranCode, "executeBack", varMap, bizTranslist, sysAbMessage, bizOperateLog, null, taskBackParam);
        completeFlowParam.setTaskId(taskId);
        completeFlowParam.setMaps(varMap);
        completeFlow(completeFlowParam,taskId);
        List<Object> paramObject = persistenceUtil.getParamObject();
        myPersistence.save(paramObject);
        //调用工作流
        //endregion
        return "1";
    }

    /**
     *
     * @description {开变销回退}
     * @param taskBackByAccountParam
     * @return void
     * @author 北陈
     * @date 2021/10/27 0027 23:18
     **/
    @Override
    public void accountBack(TaskBackByAccountParam taskBackByAccountParam) throws Exception {
        TaskBackAccountPublic accountPublic = taskBackByAccountParam.getTaskBackAccountPublic();
        String nodeName = accountPublic.getNodeName();
        String tranCode = accountPublic.getTranCode();
        String centerTellerNo = accountPublic.getCenterTellerNo();
        String postNo = accountPublic.getPostNo();
        String taskId = accountPublic.getTaskId();
        String journalNo = accountPublic.getJournalNo();
        Map<String, Object> varMap = new HashMap<>(16);
        RestTemplate restTemplate = new RestTemplate();

        SysAbMessage sysAbMessage = getSysAbMessageByJournalNo(journalNo);
        List<InfoInput> infoInputs = taskBackByAccountParam.getInfoInputs();
        String jsonStr = JSONUtil.toJsonStr(infoInputs);
        sysAbMessage.setMessage(jsonStr);

        BizTranslist bizTranslist = getBizTransListByJournalNo(journalNo);
        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setId(StringUtil.getId());
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerNo(centerTellerNo);
        bizOperateLog.setCenterNum(bizTranslist.getCenterNo());
        bizOperateLog.setOrganId(bizTranslist.getOrgCode());
        bizOperateLog.setTellerPost(postNo);
        bizOperateLog.setFlowId(bizTranslist.getFlowId());
        bizOperateLog.setTaskId(taskId);
        PersistenceUtil persistenceUtil = ReflectExecuteUtil.execute("Exec_" + tranCode, "executeBack", varMap, bizTranslist, sysAbMessage, bizOperateLog, null, taskBackByAccountParam);
        persistenceUtil.addEntity(bizTranslist);
        persistenceUtil.addEntity(sysAbMessage);
        persistenceUtil.addEntity(bizOperateLog);
        List<Object> paramObject = persistenceUtil.getParamObject();
        myPersistence.save(paramObject);
        //调用工作流提交
        CompleteFlowParam completeFlowParam = new CompleteFlowParam();
        completeFlowParam.setTaskId(taskId);
        completeFlowParam.setMaps(varMap);
        completeFlow(completeFlowParam,taskId);
    }

    @Override
    @Transactional
    public String taskComplete(TaskCompleteParam taskCompleteParam) throws Exception {
        //region 根据交易码以及节点查询数据库或者缓存中的方法名字，然后去调用相应方法
        TaskCompletePublicParam taskCompletePublicParam = taskCompleteParam.getTaskCompletePublicParam();

        String tranCode = taskCompletePublicParam.getTranCode();
        String nodeName = taskCompletePublicParam.getNodeName();
        String centerTellerNo = taskCompletePublicParam.getCenterTellerNo();
        String hint = taskCompletePublicParam.getHint();
        //通过流水号查询到流水表和日志表，记录操作信息
        String journalNo = taskCompletePublicParam.getJournalNo();
        BizTranslist bizTranslist = getBizTransListByJournalNo(journalNo);
        String postNo = taskCompletePublicParam.getPostNo();
        nodeJudgment(bizTranslist, nodeName, centerTellerNo, hint);
        SysAbMessage sysAbMessage = getSysAbMessageByJournalNo(journalNo);
        HashMap<String, Object> varMap = new HashMap<>();
        RestTemplate restTemplate = new RestTemplate();
        String taskId = taskCompletePublicParam.getTaskId();
        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerNo(centerTellerNo);
        bizOperateLog.setCenterNum(bizTranslist.getCenterNo());
        bizOperateLog.setOrganId(bizTranslist.getOrgCode());
        bizOperateLog.setTellerPost(postNo);
        bizOperateLog.setFlowId(bizTranslist.getFlowId());
        bizOperateLog.setTaskId(taskId);
        //通过反射调用相应类的相应方法
        PersistenceUtil persistenceUtil = ReflectExecuteUtil.execute("Exec_" + tranCode, "execute" + nodeName, varMap, bizTranslist, sysAbMessage, bizOperateLog, null, taskCompleteParam);
        CompleteFlowParam completeFlowParam = new CompleteFlowParam();
        completeFlowParam.setTaskId(taskId);
        completeFlowParam.setMaps(varMap);
        persistenceUtil.addEntity(bizTranslist);
        persistenceUtil.addEntity(sysAbMessage);
        persistenceUtil.addEntity(bizOperateLog);
        List<Object> paramObject = persistenceUtil.getParamObject();
        myPersistence.save(paramObject);
        String result = restTemplate.postForObject(ConstantValue.FLOWMANAGER + ConstantValue.DEPLOY_COMPLATE, completeFlowParam, String.class);
        //endregion
        Map map = JSON.parseObject(result, Map.class);
        String code = map.get("code").toString();
        if ("200".equals(code)){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("TASK_ID",taskId);
            bizTaskPoolMapper.delete(queryWrapper);
        }else {
            throw new TerminalTaskException(CenterResponseEnum.COMPLATE_TASK_ERROR);
        }
        return result;
    }

    @Override
    public void commonTaskComplete(TaskOtherCompleteParam taskCompleteParam) throws Exception {
        TaskCompletePublicParam taskChoiceParam = taskCompleteParam.getTaskCompletePublicParam();
        String tranCode = taskChoiceParam.getTranCode();
        String nodeName = taskChoiceParam.getNodeName();
        String centerTellerNo = taskChoiceParam.getCenterTellerNo();
        String hint = taskChoiceParam.getHint();
        //通过流水号查询到流水表和日志表，记录操作信息
        String journalNo = taskChoiceParam.getJournalNo();
        BizTranslist bizTranslist = getBizTransListByJournalNo(journalNo);
        nodeJudgment(bizTranslist, nodeName, centerTellerNo, hint);
        SysAbMessage sysAbMessage = getSysAbMessageByJournalNo(journalNo);
        HashMap<String, Object> varMap = new HashMap<>();
        RestTemplate restTemplate = new RestTemplate();
        String taskId = taskChoiceParam.getTaskId();
        String postNo = taskChoiceParam.getPostNo();
        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setId(StringUtil.getId());
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerNo(centerTellerNo);
        bizOperateLog.setCenterNum(bizTranslist.getCenterNo());
        bizOperateLog.setOrganId(bizTranslist.getOrgCode());
        bizOperateLog.setTellerPost(postNo);
        bizOperateLog.setFlowId(bizTranslist.getFlowId());
        bizOperateLog.setTaskId(taskId);
        bizOperateLog.setMessage(JSON.toJSONString(taskCompleteParam));

        //通过反射调用相应类的相应方法
        PersistenceUtil persistenceUtil = ReflectExecuteUtil.execute("Exec_" + tranCode, "execute" + nodeName, varMap, bizTranslist, sysAbMessage, bizOperateLog, null, taskCompleteParam);
        persistenceUtil.addEntity(bizOperateLog);
        persistenceUtil.addEntity(bizTranslist);
        CompleteFlowParam completeFlowParam = new CompleteFlowParam();
        completeFlowParam.setTaskId(taskId);
        completeFlowParam.setMaps(varMap);
        persistenceUtil.addEntity(bizTranslist);
        persistenceUtil.addEntity(sysAbMessage);
        persistenceUtil.addEntity(bizOperateLog);
        List<Object> paramObject = persistenceUtil.getParamObject();
        myPersistence.save(paramObject);
        String result = restTemplate.postForObject(ConstantValue.FLOWMANAGER + ConstantValue.DEPLOY_COMPLATE, completeFlowParam, String.class);
        Map map = JSON.parseObject(result, Map.class);
        String code = map.get("code").toString();
        if ("200".equals(code)){//判断提交是否成功
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("TASK_ID",taskId);
            bizTaskPoolMapper.delete(queryWrapper);
        }else {
            throw new TerminalTaskException(CenterResponseEnum.COMPLATE_TASK_ERROR);
        }
    }

    /**
     * @Description: ${任务终止}
     * param [taskChoiceOtherParam]
     * return java.lang.String
     * author 北陈
     * date 2021/10/22 9:30
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void taskTerminal(TaskTerminalParam taskTerminalParam) throws Exception {
        String nodeName = taskTerminalParam.getNodeName();
        String tranCode = taskTerminalParam.getTranCode();
        String centerTellerNo = taskTerminalParam.getCenterTellerNo();
        String postNo = taskTerminalParam.getPostNo();
        String taskId = taskTerminalParam.getTaskId();
        String terminalReason = taskTerminalParam.getTerminalReason();
        String terminalType = taskTerminalParam.getTerminalType();
        Map<String, Object> varMap = new HashMap<>(16);
        HashMap<String, Object> stopFlowParam = new HashMap<>(16);
        String journalNo = taskTerminalParam.getJournalNo();
        BizTranslist bizTranslist = getBizTransListByJournalNo(journalNo);
        SysAbMessage sysAbMessage = getSysAbMessageByJournalNo(journalNo);
        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setId(StringUtil.getId());
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerNo(centerTellerNo);
        bizOperateLog.setCenterNum(bizTranslist.getCenterNo());
        bizOperateLog.setOrganId(bizTranslist.getOrgCode());
        bizOperateLog.setTellerPost(postNo);
        bizOperateLog.setFlowId(bizTranslist.getFlowId());
        bizOperateLog.setTaskId(taskId);
        bizOperateLog.setOperReason(terminalReason);
        bizOperateLog.setOperateType(terminalType);
        PersistenceUtil persistenceUtil = ReflectExecuteUtil.execute("Exec_" + tranCode, "executeTerminal", varMap, bizTranslist, sysAbMessage, bizOperateLog, null, taskTerminalParam);
        persistenceUtil.addEntity(bizTranslist);
        persistenceUtil.addEntity(sysAbMessage);
        persistenceUtil.addEntity(bizOperateLog);
        List<Object> paramObject = persistenceUtil.getParamObject();
        myPersistence.save(paramObject);
        QueryWrapper<BizTaskPool> bizTaskPoolQueryWrapper = new QueryWrapper<>();
        bizTaskPoolQueryWrapper.eq("flow_id", bizTranslist.getFlowId());
        bizTaskPoolMapper.delete(bizTaskPoolQueryWrapper);
        String flowId = bizTranslist.getFlowId();
        stopFlowParam.put("processInstanceId",flowId);
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.postForObject(ConstantValue.FLOWMANAGER + ConstantValue.STOP_TASK, stopFlowParam, String.class);
        Map map = JSON.parseObject(result, Map.class);
        String code = map.get("code").toString();
        if (!"200".equals(code)){
            throw new TerminalTaskException(CenterResponseEnum.TERMINAL_TASK_ERROR);
        }
    }

    /**
     *
     * @description {开变销的提交任务}
     * @param taskCompleteByAccountParam
     * @return void
     * @author 北陈
     * @date 2021/10/27 0027 22:19
     **/
    @Override
    public void accountComplete(TaskCompleteByAccountParam taskCompleteByAccountParam) throws Exception {
        Map<String, Object> varMap = new HashMap<>();
        TaskCompleteAccountPublic accountPublic = taskCompleteByAccountParam.getTaskCompleteAccountPublic();
        String journalNo = accountPublic.getJournalNo();
        String nodeName = accountPublic.getNodeName();
        String centerTellerNo = accountPublic.getCenterTellerNo();
        String tranCode = accountPublic.getTranCode();
        String hint = accountPublic.getHint();
        String postNo = accountPublic.getPostNo();
        String taskId = accountPublic.getTaskId();
        BizTranslist bizTranslist = getBizTransListByJournalNo(journalNo);
        nodeJudgment(bizTranslist,nodeName,centerTellerNo,hint);

        SysAbMessage sysAbMessage = getSysAbMessageByJournalNo(journalNo);
        String jsonStr = JSONUtil.toJsonStr(taskCompleteByAccountParam);
        sysAbMessage.setMessage(jsonStr);

        BizOperateLog bizOperateLog = new BizOperateLog();
        bizOperateLog.setId(StringUtil.getId());
        bizOperateLog.setJournalNo(journalNo);
        bizOperateLog.setOperDate(TimeUtil.getStandardTime());
        bizOperateLog.setTellerNo(centerTellerNo);
        bizOperateLog.setCenterNum(bizTranslist.getCenterNo());
        bizOperateLog.setOrganId(bizTranslist.getOrgCode());
        bizOperateLog.setTellerPost(postNo);
        bizOperateLog.setFlowId(bizTranslist.getFlowId());
        bizOperateLog.setTaskId(taskId);

        PersistenceUtil persistenceUtil = ReflectExecuteUtil.execute("Exec_" + tranCode, "execute" + nodeName, varMap, bizTranslist, sysAbMessage, bizOperateLog, null, taskCompleteByAccountParam);
        persistenceUtil.addEntity(bizTranslist);
        persistenceUtil.addEntity(sysAbMessage);
        persistenceUtil.addEntity(bizOperateLog);
        List<Object> paramObject = persistenceUtil.getParamObject();
        myPersistence.save(paramObject);

        //调用工作流提交
        CompleteFlowParam completeFlowParam = new CompleteFlowParam();
        completeFlowParam.setTaskId(taskId);
        completeFlowParam.setMaps(varMap);
        completeFlow(completeFlowParam,taskId);
    }

    @Transactional(rollbackFor = Exception.class)
    public void completeFlow(CompleteFlowParam completeFlowParam,String taskId){
        RestTemplate restTemplate = new RestTemplate();
        String result = restTemplate.postForObject(ConstantValue.FLOWMANAGER + ConstantValue.DEPLOY_COMPLATE, completeFlowParam, String.class);
        Map map = JSON.parseObject(result, Map.class);
        String code = map.get("code").toString();
        if ("200".equals(code)){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("TASK_ID",taskId);
            bizTaskPoolMapper.delete(queryWrapper);
        }else {
            throw new TerminalTaskException(CenterResponseEnum.COMPLATE_TASK_ERROR);
        }
    }

    public void nodeJudgment(BizTranslist bizTranslist, String nodeName, String tellerNo, String hint) {
        if (PostInfoEnum.TOTALENTRY_ONE_NAME.getCode().equals(nodeName)) {
            bizTranslist.setCenterInput1Tellerno(tellerNo);
        } else if (PostInfoEnum.TOTALENTRY_TWO_NAME.getCode().equals(nodeName)) {
            bizTranslist.setCenterInput2Tellerno(tellerNo);
        } else if (PostInfoEnum.AUTH_NAME.getCode().equals(nodeName)) {
            bizTranslist.setAssignTellerno(tellerNo);
            if (StringUtils.isNotBlank(hint)) {
                bizTranslist.setRemarks(hint);
            }
        } else if (PostInfoEnum.FIXED_NAME.getCode().equals(nodeName)) {
            bizTranslist.setAuditTellerno(tellerNo);
        } else if (PostInfoEnum.REVIEW_NAME.getCode().equals(nodeName)) {
            bizTranslist.setCheckTellerNo(tellerNo);
        } else if (PostInfoEnum.INTBUS_ONE_NAME.getCode().equals(nodeName)) {
            bizTranslist.setIntbusrunTellerno1(tellerNo);
        } else if (PostInfoEnum.INTBUS_TWO_NAME.getCode().equals(nodeName)) {
            bizTranslist.setIntbusrunTellerno2(tellerNo);
        } else if (PostInfoEnum.VERIFY_ONE_NAME.getCode().equals(nodeName)) {
            bizTranslist.setVerifysealTellno1(tellerNo);
        } else if (PostInfoEnum.VERIFY_TWO_NAME.getCode().equals(nodeName)) {
            bizTranslist.setVerifysealTellno2(tellerNo);
        }
    }

    public BizTranslist getBizTransListByJournalNo(String journalNo) {
        QueryWrapper<BizTranslist> wrapper = new QueryWrapper<>();
        wrapper.eq("journal_no", journalNo);
        BizTranslist bizTranslist = bizTranslistMapper.selectOne(wrapper);
        if (ObjectUtil.isNull(bizTranslist)) {
            throw new TranslistNoExite(CenterResponseEnum.BIZ_TRANS_NO);
        } else {
            return bizTranslist;
        }
    }

    public SysAbMessage getSysAbMessageByJournalNo(String journalNo) {
        QueryWrapper<SysAbMessage> abMessageQueryWrapper = new QueryWrapper<>();
        abMessageQueryWrapper.eq("journal_no", journalNo);
        SysAbMessage sysAbMessage = sysAbMessageMapper.selectOne(abMessageQueryWrapper);
        if (ObjectUtil.isNull(sysAbMessage)) {
            throw new TranslistNoExite(CenterResponseEnum.BIZ_TRANS_NO);
        }
        return sysAbMessage;
    }

    public BizOperateLog getBizOperateLogByJournalNo(String journalNo) {
        QueryWrapper<BizOperateLog> bizOperateLogQueryWrapper = new QueryWrapper<>();
        bizOperateLogQueryWrapper.eq("journal_no", journalNo);
        BizOperateLog bizOperateLog = bizOperateLogMapper.selectOne(bizOperateLogQueryWrapper);
        if (ObjectUtil.isNull(bizOperateLog)) {
            throw new TranslistNoExite(CenterResponseEnum.BIZ_TRANS_NO);
        }
        return bizOperateLog;
    }

    public List<BizTaskPool> getListBizTaskPoolByFlowId(String flowId) {
        QueryWrapper<BizTaskPool> bizTaskPoolQueryWrapper = new QueryWrapper<>();
        return null;
    }
}
